home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: demo crash.c
-
- Purpose: This module handles crashing your machine with grace and
- style.
-
-
- MSG Demo -- graphic effects demonstration program
- Copyright (C) 1992-3 Mark Pilgrim & Dave Blumenthal
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "demo crash.h"
- #include "msg sounds.h"
- #include "msg environment.h"
- #include "msg timing.h"
-
- #define BOXSIZE 20
- #define CorrectTime 1
-
- void RestoreScreen(int oldMenuHeight)
- {
- TextFont(0);
- TextSize(0);
- TextMode(srcOr);
- FlushEvents(mDownMask+mUpMask+keyDownMask+keyUpMask+autoKeyMask, 0L);
- MBarHeight=oldMenuHeight;
- DrawMenuBar();
- PaintOne(0L,GrayRgn);
- PaintBehind(WindowList,GrayRgn);
- ShowCursor();
- ObscureCursor();
- }
-
- void CrashAndBurn(int whichSystemError)
- {
- int oldMenuHeight;
- int whichWipe;
-
- DoSound(sound_dontpanic, FALSE);
-
- ShutDownEnvironment(); /* If you have to crash a computer, */
- /* it costs nothing to be polite. */
- SysError(whichSystemError);
-
- /* in case the user manages to continue, we’ll do neat stuff here */
- HideCursor();
- oldMenuHeight=MBarHeight;
- MBarHeight=0;
- DrawMenuBar();
- SetPort(WMgrPort);
- whichWipe=(TickCount()&0x7fffffff)%6;
- switch (whichWipe)
- {
- case 0: CrashSkipaline(WMgrPort); break;
- case 1: CrashBoxIn(WMgrPort); break;
- case 2: CrashScroll(WMgrPort); break;
- case 3: CrashMrDoOutdone(WMgrPort); break;
- case 4: CrashMrDo(WMgrPort); break;
- case 5: CrashSpiral(WMgrPort); break;
- }
-
- RestoreScreen(oldMenuHeight);
-
- gDone=TRUE; /* we can’t actually continue with the program, */
- /* since, after all, the computer thinks we’ve crashed */
- }
-
- void CrashSkipaline(GrafPtr thePtr)
- {
- Rect thisone,thatone;
- int width,height;
-
- SetPort(thePtr);
-
- width=thePtr->portRect.right-thePtr->portRect.left;
- height=thePtr->portRect.bottom-thePtr->portRect.top;
-
- thisone.top=thisone.left=thatone.left=0;
- thisone.bottom=1;
- thatone.bottom=height;
- thatone.top=height-1;
- thisone.right=thatone.right=width;
-
- while (thisone.top<height)
- {
- StartTiming();
- FillRect(&thisone, black);
- FillRect(&thatone, black);
-
- thisone.top+=2; /* even row goes down by 2 */
- thisone.bottom+=2;
- thatone.top-=2; /* odd row goes up by 2 */
- thatone.bottom-=2;
- TimeCorrection(1);
- }
- }
-
- void CrashBoxIn(GrafPtr thePtr)
- {
- Rect vsource1,vsource2, hsource1, hsource2;
- int vbar,hbar;
- int width,height;
- int VBarGap, HBarGap;
-
- SetPort(thePtr);
-
- width=thePtr->portRect.right-thePtr->portRect.left;
- height=thePtr->portRect.bottom-thePtr->portRect.top;
-
- VBarGap=10;
- HBarGap=VBarGap*height/width;
-
- vbar=0;
- hbar=0;
- vsource1.top=vsource2.top=hsource2.left=hsource1.left=0; /* these */
- vsource1.bottom=vsource2.bottom=height; /* never */
- hsource1.right=hsource2.right=width; /* change */
- while (vbar<width/2+VBarGap)
- {
- StartTiming();
- vsource1.left=vbar;
- vsource1.right=vsource1.left+VBarGap;
- vsource2.right=width-vbar;
- vsource2.left=vsource2.right-VBarGap;
- hsource1.top=hbar;
- hsource1.bottom=hsource1.top+HBarGap;
- hsource2.bottom=height-hbar;
- hsource2.top=hsource2.bottom-HBarGap;
-
- FillRect(&vsource1, black);
- FillRect(&hsource1, black);
- FillRect(&vsource2, black);
- FillRect(&hsource2, black);
-
- vbar+=VBarGap;
- hbar+=HBarGap;
- TimeCorrection(3);
- }
- }
-
- void CrashScroll(GrafPtr thePtr)
- {
- int x, y;
- Rect theRect, dest;
- Rect scrollsource, scrolldest;
- int width,height;
-
- SetPort(thePtr);
-
- width=thePtr->portRect.right-thePtr->portRect.left;
- height=thePtr->portRect.bottom-thePtr->portRect.top;
-
- scrollsource=thePtr->portRect;
- scrollsource.bottom-=10; /* whole screen minus bottom strip */
- scrolldest = scrollsource;
- OffsetRect(&scrolldest, 0, 10); /* whole screen shifted down 10 */
-
- dest = thePtr->portRect;
- dest.bottom=10; /* top strip for new data */
-
- for(x = height - 10; x >= 0; x -= 10)
- {
- StartTiming();
- CopyBits(&(thePtr->portBits), &(thePtr->portBits),
- &scrollsource, &scrolldest, 0, 0L);
- FillRect(&dest, black);
-
- TimeCorrection(3);
- }
- }
-
- void CrashMrDoOutdone(GrafPtr thePtr)
- {
- int x, y;
- int vgap,hgap;
- Rect theRect, dest;
- Rect scrollsource, scrolldest;
- Rect bounds[25];
- int width,height;
-
- SetPort(thePtr);
-
- width=thePtr->portRect.right-thePtr->portRect.left;
- height=thePtr->portRect.bottom-thePtr->portRect.top;
-
- vgap=height/5;
- hgap=width/5;
-
- for (x=0; x<25; x++)
- {
- switch (x)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- bounds[x].top=0;
- break;
- case 15:
- case 16:
- case 17:
- case 18:
- case 5:
- bounds[x].top=vgap;
- break;
- case 14:
- case 23:
- case 24:
- case 19:
- case 6:
- bounds[x].top=vgap*2;
- break;
- case 13:
- case 22:
- case 21:
- case 20:
- case 7:
- bounds[x].top=vgap*3;
- break;
- case 12:
- case 11:
- case 10:
- case 9:
- case 8:
- bounds[x].top=vgap*4;
- break;
- }
- switch (x)
- {
- case 0:
- case 15:
- case 14:
- case 13:
- case 12:
- bounds[x].left=0;
- break;
- case 1:
- case 16:
- case 23:
- case 22:
- case 11:
- bounds[x].left=hgap;
- break;
- case 2:
- case 17:
- case 24:
- case 21:
- case 10:
- bounds[x].left=hgap*2;
- break;
- case 3:
- case 18:
- case 19:
- case 20:
- case 9:
- bounds[x].left=hgap*3;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- bounds[x].left=hgap*4;
- break;
- }
- bounds[x].left+=thePtr->portRect.left;
- bounds[x].top+=thePtr->portRect.top;
- bounds[x].bottom=bounds[x].top+vgap;
- bounds[x].right=bounds[x].left+hgap;
- }
-
- for (x=2; x<vgap; x+=2)
- {
- StartTiming();
- for (y=0; y<25; y++)
- {
- if (y%2) /* these scroll up */
- {
- scrollsource=bounds[y];
- scrollsource.top+=2;
- scrolldest=scrollsource;
- OffsetRect(&scrolldest,0,-2);
-
- dest=bounds[y];
- dest.top=dest.bottom-2;
-
- CopyBits(&(thePtr->portBits), &(thePtr->portBits),
- &scrollsource, &scrolldest, 0, 0L);
- FillRect(&dest, black);
- }
- else /* these scroll down */
- {
- scrollsource=bounds[y];
- scrollsource.bottom-=2;
- scrolldest = scrollsource;
- OffsetRect(&scrolldest, 0, 2);
-
- dest=bounds[y];
- dest.bottom=dest.top+2;
-
- CopyBits(&(thePtr->portBits), &(thePtr->portBits),
- &scrollsource, &scrolldest, 0, 0L);
-
- FillRect(&dest, black);
-
- }
- }
- TimeCorrection(3);
- }
-
- SetRect(&dest, thePtr->portRect.left,
- thePtr->portRect.top, thePtr->portRect.right,
- thePtr->portRect.bottom);
- FillRect(&dest, black);
- }
-
- void CrashMrDo(GrafPtr thePtr)
- {
- int x, y;
- int vgap,hgap;
- Rect theRect, dest;
- Rect scrollsource, scrolldest;
- Rect bounds[25];
- Boolean everyOther;
- int width,height;
-
- SetPort(thePtr);
-
- width=thePtr->portRect.right-thePtr->portRect.left;
- height=thePtr->portRect.bottom-thePtr->portRect.top;
-
- vgap=height/5;
- hgap=width/5;
-
- for (x=0; x<25; x++)
- {
- switch (x)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- bounds[x].top=0;
- break;
- case 15:
- case 16:
- case 17:
- case 18:
- case 5:
- bounds[x].top=vgap;
- break;
- case 14:
- case 23:
- case 24:
- case 19:
- case 6:
- bounds[x].top=vgap*2;
- break;
- case 13:
- case 22:
- case 21:
- case 20:
- case 7:
- bounds[x].top=vgap*3;
- break;
- case 12:
- case 11:
- case 10:
- case 9:
- case 8:
- bounds[x].top=vgap*4;
- break;
- }
- switch (x)
- {
- case 0:
- case 15:
- case 14:
- case 13:
- case 12:
- bounds[x].left=0;
- break;
- case 1:
- case 16:
- case 23:
- case 22:
- case 11:
- bounds[x].left=hgap;
- break;
- case 2:
- case 17:
- case 24:
- case 21:
- case 10:
- bounds[x].left=hgap*2;
- break;
- case 3:
- case 18:
- case 19:
- case 20:
- case 9:
- bounds[x].left=hgap*3;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- bounds[x].left=hgap*4;
- break;
- }
- bounds[x].left+=thePtr->portRect.left;
- bounds[x].top+=thePtr->portRect.top;
- bounds[x].bottom=bounds[x].top+vgap;
- bounds[x].right=bounds[x].left+hgap;
- }
-
- for (y=0; y<25; y++)
- {
- if (y%2) /* these scroll up */
- {
- scrollsource=bounds[y];
- scrollsource.top+=4;
- scrolldest=scrollsource;
- OffsetRect(&scrolldest,0,-4);
-
- dest=bounds[y];
- dest.top=dest.bottom-4;
-
- for (x=bounds[y].bottom-bounds[y].top-4; x>0; x-=4)
- {
- StartTiming();
- CopyBits(&(thePtr->portBits), &(thePtr->portBits),
- &scrollsource, &scrolldest, 0, 0L);
- FillRect(&dest, black);
-
- if (everyOther)
- TimeCorrection(1);
- everyOther=!everyOther;
- }
- }
- else /* these scroll down */
- {
- scrollsource=bounds[y];
- scrollsource.bottom-=4;
- scrolldest = scrollsource;
- OffsetRect(&scrolldest, 0, 4);
-
- dest=bounds[y];
- dest.bottom=dest.top+4;
-
- for(x = bounds[y].bottom-bounds[y].top-4; x > 0; x -= 4)
- {
- StartTiming();
- CopyBits(&(thePtr->portBits), &(thePtr->portBits),
- &scrollsource, &scrolldest, 0, 0L);
- FillRect(&dest, black);
-
- if (everyOther)
- TimeCorrection(1);
- everyOther=!everyOther;
- }
- }
-
- FillRect(&bounds[y], black);
- }
- }
-
- void CrashSpiral(GrafPtr thePtr)
- {
- int stop,sbottom,sleft,sright,iterrow,itercol,direction;
- Rect source;
- Boolean everyOther;
- int width,height;
-
- SetPort(thePtr);
-
- width=thePtr->portRect.right-thePtr->portRect.left;
- height=thePtr->portRect.bottom-thePtr->portRect.top;
-
- everyOther=FALSE;
- stop=0;
- sbottom=height/20-(height%20 ? 0 : 1);
- sleft=0;
- sright=width/20-(width%20 ? 0 : 1);
- direction=3;
- iterrow=stop;
- itercol=sleft;
- while ((stop<=sbottom)&&(sleft<=sright))
- {
- StartTiming();
- source.top=iterrow*20;
- source.bottom=source.top+20;
- source.left=itercol*20;
- source.right=source.left+20;
-
- FillRect(&source, black);
-
- switch (direction)
- {
- case 0: /* facing right */
- if (itercol==sright)
- {
- sbottom--;
- direction++;
- iterrow--;
- }
- else itercol++;
- break;
- case 1: /* facing up */
- if (iterrow==stop) /* that reads "s top," not "stop" */
- {
- sright--;
- direction++;
- itercol--;
- }
- else iterrow--;
- break;
- case 2: /* facing left */
- if (itercol==sleft)
- {
- stop++;
- direction++;
- iterrow++;
- }
- else itercol--;
- break;
- case 3: /* facing down */
- if (iterrow==sbottom)
- {
- sleft++;
- direction=0;
- itercol++;
- }
- else iterrow++;
- break;
- }
- if (everyOther)
- TimeCorrection(1);
- everyOther=!everyOther;
- }
- }
-